package gui;

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.FlowLayout;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.RenderingHints;
import java.awt.geom.RoundRectangle2D;

import javax.swing.Box;
import javax.swing.BoxLayout;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.SwingConstants;
import javax.swing.border.EmptyBorder;

public class GUIHomeRight extends JPanel{
	
	private static final long serialVersionUID = 1L;
	private long currentTime;
	private JLabel lbMSTS, lbName, lbDOB, lbCMND,lbRoom, lbRemainTime;
	public GUIHomeRight() {
		setOpaque(false);
		lbMSTS = new JLabel(" ",SwingConstants.RIGHT);
		lbMSTS.setFont(lbMSTS.getFont().deriveFont(24f));
		lbMSTS.setForeground(new Color(250,250,250));
		
		lbName = new JLabel(" ");
		lbName.setFont(lbMSTS.getFont().deriveFont(24f));
		lbName.setForeground(new Color(250,250,250));
		
		lbDOB = new JLabel(" ");
		lbDOB.setFont(lbMSTS.getFont().deriveFont(24f));
		lbDOB.setForeground(new Color(250,250,250));
		
		lbCMND = new JLabel(" ");
		lbCMND.setFont(lbMSTS.getFont().deriveFont(24f));
		lbCMND.setForeground(new Color(250,250,250));
		
		lbRoom = new JLabel(" ");
		lbRoom.setFont(lbMSTS.getFont().deriveFont(24f));
		lbRoom.setForeground(new Color(250,250,250));
		
		lbRemainTime = new JLabel("00:00");
		lbRemainTime.setFont(lbMSTS.getFont().deriveFont(60f));
		lbRemainTime.setForeground(new Color(250,250,250,200));
		
		setLayout(new BorderLayout());
		
		JPanel topPanel = new JPanel();
		topPanel.setBorder(new EmptyBorder(10, 20, 10, 10));
		topPanel.setLayout(new BoxLayout(topPanel, BoxLayout.Y_AXIS));
		topPanel.setOpaque(false);
		
		JLabel temp = new JLabel("MSTS");
		temp.setFont(temp.getFont().deriveFont(20f));
		temp.setForeground(CustomJButton.BLUE);
		topPanel.add(temp);
		topPanel.add(lbMSTS);
		topPanel.add(Box.createVerticalStrut(15));
		
		temp = new JLabel("Họ tên");
		temp.setFont(temp.getFont().deriveFont(20f));
		temp.setForeground(CustomJButton.BLUE);
		topPanel.add(temp);
		topPanel.add(lbName);
		topPanel.add(Box.createVerticalStrut(15));
		
		temp = new JLabel("CMND");
		temp.setFont(temp.getFont().deriveFont(20f));
		temp.setForeground(CustomJButton.BLUE);
		topPanel.add(temp);
		topPanel.add(lbCMND);
		topPanel.add(Box.createVerticalStrut(15));
		
		temp = new JLabel("Ngày sinh");
		temp.setFont(temp.getFont().deriveFont(20f));
		temp.setForeground(CustomJButton.BLUE);
		topPanel.add(temp);
		topPanel.add(lbDOB);
		topPanel.add(Box.createVerticalStrut(15));
		
		temp = new JLabel("Phòng thi");
		temp.setFont(temp.getFont().deriveFont(20f));
		temp.setForeground(CustomJButton.BLUE);
		topPanel.add(temp);
		topPanel.add(lbRoom);
		topPanel.add(Box.createVerticalStrut(15));
		
		add(topPanel,BorderLayout.NORTH);
		
		JPanel bottomPanel = new JPanel(new FlowLayout(FlowLayout.CENTER));
		bottomPanel.setOpaque(false);
		bottomPanel.add(lbRemainTime);
		
		add(bottomPanel,BorderLayout.SOUTH);
	}
	
	public void setMSTS(String string){
		this.lbMSTS.setText(string);
	}
	
	public void setName(String string){
		this.lbName.setText(string);
	}
	
	public void setDateOfBirth(String string){
		this.lbDOB.setText(string);
	}
	
	public void setCMND(String string){
		this.lbCMND.setText(string);
	}
	
	public void setRoom(String string){
		this.lbRoom.setText(string);
	}
	
	public void setRemainingTime(long param){
		long min,sec;
		this.currentTime = param;
		min = param/60;
		sec = param - min*60;
		String temp = min + ":" + String.format("%02d", sec);
		if(min<10){
			temp = String.format("%02d", min) + ":" + String.format("%02d", sec);
		}
		this.lbRemainTime.setText(temp);
	}
	
	public void reduceOneSec(){
		setRemainingTime(currentTime-1);
	}

	@Override
	protected void paintComponent(Graphics g) {
		Graphics2D g2d;
		g2d = (Graphics2D) g;
		
		g2d.setRenderingHint(
			    RenderingHints.KEY_ANTIALIASING,
			    RenderingHints.VALUE_ANTIALIAS_ON);
		
		RoundRectangle2D roundedRectangle = new RoundRectangle2D.Float(0, 0, this.getWidth()-1, this.getHeight()-1, 15, 15);
		
		g2d.setColor(new Color(60, 60, 60));
		g2d.fill(roundedRectangle);
		
		g2d.setColor(new Color(244, 244, 244, 244));
		g2d.draw(roundedRectangle);
		g2d.setRenderingHint(
			    RenderingHints.KEY_ANTIALIASING,
			    RenderingHints.VALUE_ANTIALIAS_DEFAULT);
		super.paintComponent(g);
	}
	
	
}
